package com.cy.pj.notice.service.impl;

import com.cy.pj.common.exception.ServiceException;
import com.cy.pj.notice.dao.SysNoticeDao;
import com.cy.pj.notice.service.SysNoticeService;
import com.cy.pj.notice.pojo.SysNotice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service//表示一个业务层对象，spring的一个bean
//@Component//一般组件
public class SysNoticeServiceImpl implements SysNoticeService {

    @Autowired
    private SysNoticeDao sysNoticeDao;

    @Override
    public List<SysNotice> findNotices(SysNotice sysNotice) {
        List<SysNotice> list = sysNoticeDao.selectNotices(sysNotice);
        return list;
    }

    @Override
    public int saveNotice(SysNotice sysNotice) {
        int rows = sysNoticeDao.insertNotice(sysNotice);
        return rows;
    }

    @Override
    public SysNotice findById(Long id) {
        SysNotice sysNotice = sysNoticeDao.findById(id);
        if (sysNotice == null) {
            throw new ServiceException("该通知不存在");
        }
        return sysNotice;
    }

    @Override
    public int updateNotice(SysNotice sysNotice) {
        return sysNoticeDao.updataNotice(sysNotice);
    }

    @Override
    public int deleteById(Long... id) {
        int rows = sysNoticeDao.deleteNotice(id);
        return rows;
    }
}
